package userinfo;
import util.Info;
import java.util.Scanner;
import static util.Info.userlLogin;
import static util.Info.yue;

/**
 * @author 嫣然
 */
public class Login {
	static int useid=0;
	//饭卡余额
	static int cardMoney=0;
	/**
	 * 登录验证
	 */
	public static void login () {
		Scanner in=new Scanner(System.in);
		System.out.println("输入你的学号：");
		int id=in.nextInt();
		System.out.println("输入你的密码：");
		String password=in.next();
		//
		useid=id;
		//验证登录
		int count=userlLogin(id,password);
		if (count>0){
			user();
		}else{
			System.out.println("学号或密码输入错误，请重试");
			login();
		}
	}

	public static void user() {
		Scanner in=new Scanner(System.in);
		System.out.println("----------------欢迎使用饭卡系统----------------");
		System.out.println("1.充值饭卡     	      请按1");
		System.out.println("2.查询余额     	      请按2");
		System.out.println("3.查询信息     	      请按3");
		System.out.println("4.饭卡消费    	      请按4");
		System.out.println("5.查询银行卡余额     	  请按5");
		System.out.println("6.修改信息   	          请按6");
		System.out.println("7.退出系统     	      请按7");
		System.out.println("请输入：");
		int count=in.nextInt();
		switch (count) {
		case 1:
			System.out.println("请输入你要充值的金额：");
			int count1=in.nextInt();
			cardMoney=count1+cardMoney;
			int c=Info.cardmoney(cardMoney,useid);
			//银行卡余额
			int money=Info.money(useid);
			int now=money-cardMoney;
			Info.setMoney(now,useid);
			if (c>0||Info.money(useid)>=0){
				System.out.println("充值成功");
			}else {
				System.out.println("充值失败");
			}
			user();
			break;
		case 2:
			System.out.println("饭卡余额："+yue(useid));
			user();
			break;
		case 3:
			Register.user(useid);
			user();
			break;
		case 4:
			//余额
			int now1=yue(useid);
			System.out.println("余额："+yue(useid));
			System.out.println("请输入你要花费的金额：");
			int useMoney=in.nextInt();
			int use=now1-useMoney;
			//存入数据库消费后的钱
			Info.usemoney(use,useid);
			if (use<0){
				System.out.println("余额不足，请充值");
			}else {
				System.out.println("您已消费"+useMoney+"元,余额："+use);
			}
			user();
			break;
		case 5:
			int money1=Info.money(useid);
			System.out.println("银行卡余额："+money1);
			user();
			break;
		case 6:
			Register.user(useid);
			Register.setuser(useid);
			user();
			break;
		case 7:
			System.out.println("您已退出");
			System.exit(0);
			break;
		default:
			break;
		}
	}
}
